<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>Java基础学习（1） | SuperXCR</title><meta name="author" content="SuperXCR"><meta name="copyright" content="SuperXCR"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="变量和类型1.1 变量Java是面向对象的语言，Java把一切内容(字符串，数字，布尔，日期，时间)都用对象表示 在Java世界中 变量的内容就是对象 1.2 赋值1String say &#x3D; &quot;Hello SuperXCR&quot;; 重复赋值 12345String name;name &#x3D; &quot;小明&quot;；System.out.println(name);name &#x3D;">
<meta property="og:type" content="article">
<meta property="og:title" content="Java基础学习（1）">
<meta property="og:url" content="https://liqur.xyz/SuperXCR/24bd5933.html">
<meta property="og:site_name" content="SuperXCR">
<meta property="og:description" content="变量和类型1.1 变量Java是面向对象的语言，Java把一切内容(字符串，数字，布尔，日期，时间)都用对象表示 在Java世界中 变量的内容就是对象 1.2 赋值1String say &#x3D; &quot;Hello SuperXCR&quot;; 重复赋值 12345String name;name &#x3D; &quot;小明&quot;；System.out.println(name);name &#x3D;">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://liqur-1309874423.cos.ap-shanghai.myqcloud.com/java6.png">
<meta property="article:published_time" content="2022-08-31T02:00:00.000Z">
<meta property="article:modified_time" content="2022-09-15T13:50:34.406Z">
<meta property="article:author" content="SuperXCR">
<meta property="article:tag" content="Java">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://liqur-1309874423.cos.ap-shanghai.myqcloud.com/java6.png"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://liqur.xyz/SuperXCR/24bd5933.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Java基础学习（1）',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2022-09-15 21:50:34'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><!-- hexo injector head_end start --><link rel="stylesheet" href="https://cdn.cbd.int/hexo-butterfly-clock-anzhiyu/lib/clock.min.css" /><link rel="stylesheet" href="https://cdn.cbd.int/hexo-butterfly-tag-plugins-plus@latest/lib/assets/font-awesome-animation.min.css" media="defer" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.cbd.int/hexo-butterfly-tag-plugins-plus@latest/lib/tag_plugins.css" media="defer" onload="this.media='all'"><script src="https://cdn.cbd.int/hexo-butterfly-tag-plugins-plus@latest/lib/assets/carousel-touch.js"></script><!-- hexo injector head_end end --><meta name="generator" content="Hexo 5.4.2"></head><body><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">16</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">15</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">8</div></a></div><hr/></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://liqur-1309874423.cos.ap-shanghai.myqcloud.com/java6.png')"><nav id="nav"><span id="blog-info"><a href="/" title="SuperXCR"><span class="site-name">SuperXCR</span></a></span><div id="menus"><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Java基础学习（1）</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2022-08-31T02:00:00.000Z" title="发表于 2022-08-31 10:00:00">2022-08-31</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2022-09-15T13:50:34.406Z" title="更新于 2022-09-15 21:50:34">2022-09-15</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/Java/">Java</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Java基础学习（1）"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h3 id="变量和类型"><a href="#变量和类型" class="headerlink" title="变量和类型"></a>变量和类型</h3><h4 id="1-1-变量"><a href="#1-1-变量" class="headerlink" title="1.1 变量"></a>1.1 变量</h4><p>Java是面向对象的语言，Java把一切内容(字符串，数字，布尔，日期，时间)都用对象表示</p>
<p>在Java世界中 <strong>变量的内容就是对象</strong></p>
<h4 id="1-2-赋值"><a href="#1-2-赋值" class="headerlink" title="1.2 赋值"></a>1.2 赋值</h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">String say = &quot;Hello SuperXCR&quot;;</span><br></pre></td></tr></table></figure>
<p>重复赋值</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">String name;</span><br><span class="line">name = <span class="string">&quot;小明&quot;</span>；</span><br><span class="line">System.out.println(name);</span><br><span class="line">name = <span class="string">&quot;小红&quot;</span>;</span><br><span class="line">System.out.println(name);</span><br></pre></td></tr></table></figure>
<h4 id="1-3-数据类型"><a href="#1-3-数据类型" class="headerlink" title="1.3 数据类型"></a>1.3 数据类型</h4><h5 id="字符串"><a href="#字符串" class="headerlink" title="字符串"></a>字符串</h5><p>Java类型中 String 的值需要 “ “包围。</p>
<h5 id="数字"><a href="#数字" class="headerlink" title="数字"></a>数字</h5><ul>
<li>小整数    int</li>
<li>大整数    long</li>
<li>浮点数    double</li>
</ul>
<p>int 与long 的区别</p>
<p><strong>int</strong></p>
<p><code>最小值 : Integer.MIN_VALUE=-2147483648 (-2的31次方)</code></p>
<p><code>最大值 : Integer.MIN_VALUE=2147483647 (2的31次方-1)</code></p>
<p><strong>long</strong></p>
<p><code>最小值 : Long.MIN_VALUE=-2147483648 (-2的63次方)</code></p>
<p><code>最大值 : Long.MIN_VALUE=2147483647 (2的63次方-1)</code></p>
<p>注意long类型赋值的时候要在数字最后跟上一个小写的 l (是字母L)</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">long</span> <span class="variable">num</span> <span class="operator">=</span> <span class="number">78900000123l</span>;</span><br></pre></td></tr></table></figure>
<h5 id="布尔"><a href="#布尔" class="headerlink" title="布尔"></a>布尔</h5><p>比如说</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 是否允许</span></span><br><span class="line"><span class="type">boolean</span> <span class="variable">isAllow</span> <span class="operator">=</span> ture;</span><br></pre></td></tr></table></figure>
<h4 id="1-4-运算符"><a href="#1-4-运算符" class="headerlink" title="1.4 运算符"></a>1.4 运算符</h4><p>可以通过 <strong>变量＋数字</strong> 来完成计算</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">int</span> <span class="variable">second</span> <span class="operator">=</span> <span class="number">1</span>*<span class="number">60</span>*<span class="number">60</span>;</span><br><span class="line"></span><br><span class="line">System.out.println(<span class="string">&quot;second&quot;</span>);</span><br><span class="line"><span class="comment">//也可以</span></span><br><span class="line"><span class="type">int</span> <span class="variable">unit</span> <span class="operator">=</span> <span class="number">60</span>;</span><br><span class="line"><span class="type">int</span> <span class="variable">hour</span> <span class="operator">=</span> <span class="number">1</span>;</span><br><span class="line"><span class="type">int</span> <span class="variable">second</span> <span class="operator">=</span> hour * unit * unit;</span><br><span class="line"></span><br><span class="line">System.out.println(second);</span><br><span class="line"></span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//计算平均分</span></span><br><span class="line"><span class="type">int</span> <span class="variable">total</span> <span class="operator">=</span> <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="variable">u1</span> <span class="operator">=</span> <span class="number">80</span>;</span><br><span class="line">total=total+u1;</span><br><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="variable">u2</span> <span class="operator">=</span> <span class="number">90</span>;</span><br><span class="line">total=total+u2;</span><br><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="variable">u3</span> <span class="operator">=</span> <span class="number">50</span>;</span><br><span class="line">total=total+u3;</span><br><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="variable">u4</span> <span class="operator">=</span> <span class="number">65</span>;</span><br><span class="line">total=total+u4;</span><br><span class="line"></span><br><span class="line"><span class="type">int</span> <span class="variable">average</span> <span class="operator">=</span> total/<span class="number">4</span>;</span><br><span class="line"></span><br><span class="line">System.out.println(average);</span><br></pre></td></tr></table></figure>
<h6 id="注意"><a href="#注意" class="headerlink" title="注意"></a>注意</h6><ol>
<li>Java执行整数除法，即两个整数相除结果也为整数</li>
<li>计算浮点型的话，用double</li>
<li>字符串可通过 + 连接成新的字符串</li>
</ol>
<h4 id="1-5-数学函数"><a href="#1-5-数学函数" class="headerlink" title="1.5 数学函数"></a>1.5 数学函数</h4><h5 id="1-5-1-获取随机数"><a href="#1-5-1-获取随机数" class="headerlink" title="1.5.1 获取随机数"></a>1.5.1 获取随机数</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//获取一个随机数</span></span><br><span class="line"><span class="type">double</span> <span class="variable">value</span> <span class="operator">=</span> Math.random(); </span><br><span class="line"><span class="comment">//Math.random()方法返回一个随机值 随即值的范围是0.0 =&lt;Math.random&lt;1.0</span></span><br><span class="line">System.out.println(value);</span><br></pre></td></tr></table></figure>
<h5 id="1-5-2-类型转换方法"><a href="#1-5-2-类型转换方法" class="headerlink" title="1.5.2 类型转换方法"></a>1.5.2 类型转换方法</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">double</span> <span class="variable">value</span> <span class="operator">=</span> Math.random();</span><br><span class="line"><span class="type">int</span> <span class="variable">nValue</span> <span class="operator">=</span> (<span class="type">int</span>) (value*<span class="number">10</span>);</span><br><span class="line">System.out.println(nValue);</span><br></pre></td></tr></table></figure>
<h4 id="1-5-自定义方法"><a href="#1-5-自定义方法" class="headerlink" title="1.5 自定义方法"></a>1.5 自定义方法</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// public（公共的） static（静态） void（空类型）</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> 方法名称(方法参数)&#123;</span><br><span class="line">  代码块</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>小驼峰</p>
<p>方法名遵守的是小驼峰</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 密码</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">password</span><span class="params">()</span>&#123;</span><br><span class="line">  <span class="comment">//代码块</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// 我的文档</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">myDocument</span><span class="params">()</span>&#123;</span><br><span class="line">  <span class="comment">//代码块</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h4 id="1-6-自定义方法调用"><a href="#1-6-自定义方法调用" class="headerlink" title="1.6 自定义方法调用"></a>1.6 自定义方法调用</h4><p>方法调用</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line">        System.out.println(<span class="string">&quot;测试&quot;</span>);</span><br><span class="line"></span><br><span class="line">        newLine();</span><br><span class="line">        newLine();</span><br><span class="line">        System.out.println(<span class="string">&quot;结束&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">newLine</span> <span class="params">()</span>&#123;</span><br><span class="line">        newWord();</span><br><span class="line">        System.out.println(<span class="string">&quot;Hello&quot;</span>);</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">newWord</span> <span class="params">()</span>&#123;</span><br><span class="line">        System.out.println(<span class="string">&quot;-----------&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h4 id="1-7-方法参数"><a href="#1-7-方法参数" class="headerlink" title="1.7 方法参数"></a>1.7 方法参数</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//在main函数下；</span></span><br><span class="line">&#123;</span><br><span class="line">    code( <span class="string">&quot;Apple&quot;</span>);</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">code</span><span class="params">(String food)</span>&#123;<span class="comment">//就是指定变量类型；</span></span><br><span class="line">    System.out.println(code);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>图片示例</p>
<p><img src="https://liqur-1309874423.cos.ap-shanghai.myqcloud.com/method1.svg" alt=""></p>
<h5 id="形参"><a href="#形参" class="headerlink" title="形参"></a>形参</h5><p>声明变量</p>
<h5 id="实参"><a href="#实参" class="headerlink" title="实参"></a>实参</h5><p>传递变量</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//直接传值</span></span><br><span class="line">random(<span class="number">100000</span>);</span><br><span class="line"></span><br><span class="line"><span class="comment">//传递变量</span></span><br><span class="line"><span class="type">int</span> <span class="variable">len</span> <span class="operator">=</span> <span class="number">100000</span>;</span><br><span class="line">random(len);</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h4 id="1-8-多参数方法"><a href="#1-8-多参数方法" class="headerlink" title="1.8 多参数方法"></a>1.8 多参数方法</h4><p>代码示例</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">MessageCode</span> &#123;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line">    <span class="type">String</span> <span class="variable">text</span> <span class="operator">=</span> <span class="string">&quot;亲爱的SuperXCR用户，你本次的验证码是&quot;</span>;</span><br><span class="line">    code(text,<span class="number">1000</span>);<span class="comment">//形参之间用 ，隔开；</span></span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">code</span><span class="params">(String text,<span class="type">int</span> len)</span>&#123;</span><br><span class="line">      <span class="type">int</span> <span class="variable">code</span> <span class="operator">=</span> (<span class="type">int</span>)((Math.random()+<span class="number">1</span>)*len);</span><br><span class="line">      System.out.println(text+<span class="string">&quot;【&quot;</span>+code+<span class="string">&quot;】&quot;</span>);</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h3 id="逻辑语句"><a href="#逻辑语句" class="headerlink" title="逻辑语句"></a>逻辑语句</h3><h4 id="2-1-条件执行"><a href="#2-1-条件执行" class="headerlink" title="2.1 条件执行"></a>2.1 条件执行</h4><p>关键字 if 后括号中的代码叫做：<strong>条件表达式</strong> 如果为真，大括号中的语句就会执行；反之，则什么都不会发生；</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span>(表达式)&#123;</span><br><span class="line">    </span><br><span class="line">    代码块</span><br><span class="line">        </span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//条件表达式可以包含任意的比较比较运算符</span></span><br><span class="line">x == y   <span class="comment">// x 等于 y</span></span><br><span class="line">x != y   <span class="comment">// x 不等于 y</span></span><br><span class="line">x &gt;  y   <span class="comment">// x 大于 y</span></span><br><span class="line">x &lt;  y   <span class="comment">// x 小于 y</span></span><br><span class="line">x &gt;= y   <span class="comment">// x 大于等于 y</span></span><br><span class="line">x &lt;= y   <span class="comment">// x 小于等于 y</span></span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//注意</span></span><br><span class="line">Java中 = 符号是赋值运算符，这个我们在变量那个章节里学习到过。== 是判断是否相同的比较运算符</span><br><span class="line"></span><br><span class="line">Java中没有 =&lt; 和 =&gt; 这两种写法，这是错误的</span><br><span class="line"></span><br><span class="line">此外， Java中比较运算符的左边和右边的对象类型必须一样的，<span class="type">int</span>整数只能和<span class="type">int</span>整数比较，双精度<span class="type">double</span>只能和<span class="type">double</span>比较</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h4 id="2-2-选择执行"><a href="#2-2-选择执行" class="headerlink" title="2.2 选择执行"></a>2.2 选择执行</h4><p>也就是if else语句</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span>(条件表达式)&#123;</span><br><span class="line">  代码语句</span><br><span class="line">&#125;<span class="keyword">else</span>&#123;</span><br><span class="line">  代码语句</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//奇数偶数判断</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Condition</span>&#123;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span>&#123;</span><br><span class="line">    number(<span class="number">4</span>);</span><br><span class="line">    number(<span class="number">5</span>);</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">number</span><span class="params">(<span class="type">int</span> x)</span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span>(x % <span class="number">2</span> == <span class="number">0</span>)&#123;</span><br><span class="line">      System.out.println(x+<span class="string">&quot;是偶数&quot;</span>);</span><br><span class="line">    &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">      System.out.println(x+<span class="string">&quot;是奇数&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h4 id="2-3-条件判断链"><a href="#2-3-条件判断链" class="headerlink" title="2.3 条件判断链"></a>2.3 条件判断链</h4><p>判断链也就是通过一层一层的判断</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">report</span><span class="params">(String name,<span class="type">double</span> score)</span>&#123;</span><br><span class="line">  <span class="keyword">if</span>(score &gt;= <span class="number">90</span>)&#123;</span><br><span class="line">    System.out.println(name+<span class="string">&quot;,你本次的成绩为优秀&quot;</span>);</span><br><span class="line">  &#125; <span class="keyword">else</span> <span class="keyword">if</span>(score &gt;= <span class="number">80</span>)&#123;</span><br><span class="line">    System.out.println(name+<span class="string">&quot;,你本次的成绩为良好&quot;</span>);</span><br><span class="line">  &#125; <span class="keyword">else</span> <span class="keyword">if</span>(score &gt;= <span class="number">60</span>)&#123;</span><br><span class="line">    System.out.println(name+<span class="string">&quot;,你本次的成绩为及格&quot;</span>);</span><br><span class="line">  &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">    System.out.println(name+<span class="string">&quot;,你本次的成绩为不通过&quot;</span>);</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h4 id="2-4-嵌套条件"><a href="#2-4-嵌套条件" class="headerlink" title="2.4 嵌套条件"></a>2.4 嵌套条件</h4><p>嵌套就是在 if else 中嵌套if else </p>
<p>代码示例如下</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">StudentReport</span> &#123;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span>&#123;</span><br><span class="line"></span><br><span class="line">    report(<span class="string">&quot;小明&quot;</span>,<span class="number">80</span>);</span><br><span class="line">    report(<span class="string">&quot;小王&quot;</span>,<span class="number">90</span>);</span><br><span class="line">    report(<span class="string">&quot;小四&quot;</span>,<span class="number">70</span>);</span><br><span class="line">    report(<span class="string">&quot;小五&quot;</span>,<span class="number">50</span>);</span><br><span class="line">    report(<span class="string">&quot;小六&quot;</span>,<span class="number">40</span>);</span><br><span class="line"></span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">report</span><span class="params">(String name,<span class="type">double</span> score)</span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span>(score &gt;= <span class="number">60</span>)&#123;</span><br><span class="line">      message(name);</span><br><span class="line">      <span class="keyword">if</span>(score &gt;= <span class="number">90</span>)&#123;</span><br><span class="line">        System.out.println(name+<span class="string">&quot;,你本次的成绩为优秀&quot;</span>);</span><br><span class="line">      &#125; <span class="keyword">else</span> <span class="keyword">if</span>(score &gt;= <span class="number">80</span>)&#123;</span><br><span class="line">        System.out.println(name+<span class="string">&quot;,你本次的成绩为良好&quot;</span>);</span><br><span class="line">      &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">        System.out.println(name+<span class="string">&quot;,你本次的成绩为及格&quot;</span>);</span><br><span class="line">      &#125;</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">      System.out.println(name+<span class="string">&quot;,你本次的成绩为不通过&quot;</span>);</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">message</span><span class="params">(String name)</span>&#123;</span><br><span class="line">    System.out.println(name+<span class="string">&quot;恭喜你成功进阶&quot;</span>);</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h4 id="2-5-返回语句"><a href="#2-5-返回语句" class="headerlink" title="2.5 返回语句"></a>2.5 返回语句</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">plan</span><span class="params">(<span class="type">double</span> temperature)</span>&#123;</span><br><span class="line"></span><br><span class="line">  System.out.println(<span class="string">&quot;准备出门去学校&quot;</span>);</span><br><span class="line"></span><br><span class="line">  <span class="keyword">if</span>(temperature&gt;<span class="number">38</span>)&#123;</span><br><span class="line">    <span class="comment">// 体温超过38度，属于发烧，忌运动</span></span><br><span class="line">    <span class="keyword">return</span>;</span><br><span class="line">  &#125;</span><br><span class="line">  </span><br><span class="line">  System.out.println(<span class="string">&quot;去操场踢球&quot;</span>);</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>返回语句也就是通过if判断后，如果进入if语句后，在return后就不会在执行下面的语句</p>
<h4 id="2-6-递归"><a href="#2-6-递归" class="headerlink" title="2.6 递归"></a>2.6 递归</h4><p>一个方法也可以调用它本身，这叫做递归，这种方法称为递归方法;</p>
<p>递归实例</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">CountDown</span> &#123;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line">    count(<span class="number">3</span>);</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">count</span><span class="params">(<span class="type">int</span> number)</span> &#123;</span><br><span class="line">    System.out.println(number);</span><br><span class="line">    number = number - <span class="number">1</span>;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">if</span> (number == <span class="number">0</span>) &#123;</span><br><span class="line">      System.out.println(<span class="string">&quot;程序执行完毕&quot;</span>);</span><br><span class="line">      <span class="keyword">return</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    count(number);<span class="comment">//递归用法;</span></span><br><span class="line"></span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h3 id="有返回值方法"><a href="#有返回值方法" class="headerlink" title="有返回值方法"></a>有返回值方法</h3><h4 id="3-1-返回值"><a href="#3-1-返回值" class="headerlink" title="3.1 返回值"></a>3.1 返回值</h4><p>random这个方法Java源代码</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">static</span> <span class="type">double</span> <span class="title function_">random</span><span class="params">()</span> &#123;</span><br><span class="line">   <span class="keyword">return</span> RandomNumberGeneratorHolder.randomNumberGenerator.nextDouble();</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>关于return的知识点</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//return对应的类型相同</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">static</span> <span class="type">int</span> <span class="title function_">result</span><span class="params">()</span>&#123;<span class="comment">//此处为整型，还可以为String，double，boolean</span></span><br><span class="line"></span><br><span class="line">  <span class="keyword">return</span> <span class="string">&quot;整型&quot;</span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<ul>
<li>4位验证码判断</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">Captcha</span>&#123;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span>&#123;</span><br><span class="line">    <span class="comment">// 得到验证码</span></span><br><span class="line">    <span class="type">int</span> <span class="variable">codeValue</span> <span class="operator">=</span> code(<span class="number">1000</span>);</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 如果 codeValue 在1000和9999之间，那么就是正确的4位随机数</span></span><br><span class="line">    <span class="keyword">if</span>(codeValue &gt;= <span class="number">1000</span> )&#123;</span><br><span class="line">      <span class="keyword">if</span>(codeValue &lt;= <span class="number">9999</span>)&#123;</span><br><span class="line">        System.out.println(<span class="string">&quot;本次的验证码是:&quot;</span> + codeValue);</span><br><span class="line">      &#125;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">  * 得到验证码</span></span><br><span class="line"><span class="comment">  */</span></span><br><span class="line">  <span class="keyword">public</span> <span class="keyword">static</span> <span class="type">int</span> <span class="title function_">code</span><span class="params">(<span class="type">int</span> len)</span>&#123;</span><br><span class="line">    <span class="comment">// 得到随机数结果</span></span><br><span class="line">    <span class="type">double</span> <span class="variable">val</span> <span class="operator">=</span> Math.random();</span><br><span class="line">    <span class="comment">// 随机数结果*9+1 然后再乘以位数得到验证码</span></span><br><span class="line">    <span class="type">int</span> <span class="variable">result</span> <span class="operator">=</span> (<span class="type">int</span>)((val * <span class="number">9</span> + <span class="number">1</span>) * len);</span><br><span class="line">    <span class="keyword">return</span> result;</span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<ul>
<li>奖金类发放，判断</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">BonusDemo</span>&#123;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span>&#123;</span><br><span class="line">     <span class="type">int</span> <span class="variable">amount</span> <span class="operator">=</span> bonus(<span class="number">0</span>);</span><br><span class="line">     System.out.println(amount);</span><br><span class="line"></span><br><span class="line">     amount = bonus(<span class="number">80000</span>);</span><br><span class="line">     System.out.println(amount);</span><br><span class="line"></span><br><span class="line">     amount = bonus(<span class="number">280000</span>);</span><br><span class="line">     System.out.println(amount);</span><br><span class="line"></span><br><span class="line">     amount = bonus(<span class="number">500000</span>);</span><br><span class="line">     System.out.println(amount);</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">  <span class="comment">/**</span></span><br><span class="line"><span class="comment">  *   计算奖金</span></span><br><span class="line"><span class="comment">  */</span></span><br><span class="line">  <span class="keyword">public</span> <span class="keyword">static</span> <span class="type">int</span> <span class="title function_">bonus</span><span class="params">(<span class="type">int</span> amount)</span>&#123;</span><br><span class="line">    <span class="keyword">if</span> (amount&lt;<span class="number">100000</span>)&#123;</span><br><span class="line">      <span class="keyword">return</span> amount*<span class="number">10</span>/<span class="number">100</span>;</span><br><span class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span>(amount&gt;<span class="number">300000</span>)&#123;</span><br><span class="line">      <span class="keyword">return</span> amount*<span class="number">7</span>/<span class="number">100</span>;</span><br><span class="line">    &#125; <span class="keyword">else</span> <span class="keyword">if</span>(amount&gt;=<span class="number">100000</span>)&#123;</span><br><span class="line">      <span class="keyword">return</span> amount*<span class="number">9</span>/<span class="number">100</span>;</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">      <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">    &#125;</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h4 id="3-2-布尔-amp-amp-逻辑运算符"><a href="#3-2-布尔-amp-amp-逻辑运算符" class="headerlink" title="3.2 布尔&amp;&amp;逻辑运算符"></a>3.2 布尔&amp;&amp;逻辑运算符</h4><ol>
<li>&amp;&amp;  ||  ！三者运用</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span>(x&gt;<span class="number">0</span> &amp;&amp; x &lt;<span class="number">10</span>)&#123;</span><br><span class="line">  <span class="comment">// 表示 x 大于0 并且 x小于10时才为真</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span>(x == <span class="number">60</span> || x == <span class="number">80</span>)&#123;</span><br><span class="line">  <span class="comment">// 表示 x 等于60 或者 x 等于80 都为真</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span>(x!=<span class="number">0</span>)&#123;</span><br><span class="line">  <span class="comment">// 表示x不等于0的时候</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<ol>
<li>！运用</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//可以用 ！对boolean进行否定;</span></span><br><span class="line"><span class="type">boolean</span> <span class="variable">isPass</span> <span class="operator">=</span> <span class="literal">false</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span>(!isPass)&#123;</span><br><span class="line">  System.out.println(<span class="string">&quot;通过考试&quot;</span>);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<ol>
<li>还可以多次组合</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span>(x == <span class="number">60</span> || x == <span class="number">80</span> || x == <span class="number">90</span>)&#123;</span><br><span class="line">  <span class="comment">// 表示 x等于60 或者x等于80 或者x等于90为真</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h3 id="循环"><a href="#循环" class="headerlink" title="循环"></a>循环</h3><h4 id="4-1-自增和自减"><a href="#4-1-自增和自减" class="headerlink" title="4.1 自增和自减"></a>4.1 自增和自减</h4><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//自减，就是</span></span><br><span class="line">        number = number - <span class="number">1</span>；</span><br><span class="line">        number --;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//自增</span></span><br><span class="line">   number = number + <span class="number">1</span>;</span><br><span class="line">   number ++;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h4 id="4-2-数组"><a href="#4-2-数组" class="headerlink" title="4.2 数组"></a>4.2 数组</h4><p>int[ ] 表示”整型数组”类，String[ ] 表示”字符串”</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 声明一个 int 数组的变量，数组大小为6</span></span><br><span class="line"><span class="type">int</span>[] numbers = <span class="keyword">new</span> <span class="title class_">int</span>[<span class="number">6</span>];</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>创建好数组变量后，可以借助[下标]来完成操作</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 声明一个 int 数组的变量，数组大小为6</span></span><br><span class="line"><span class="type">int</span>[] numbers = <span class="keyword">new</span> <span class="title class_">int</span>[<span class="number">6</span>];</span><br><span class="line"></span><br><span class="line">numbers[<span class="number">0</span>] = <span class="number">1</span>;</span><br><span class="line">numbers[<span class="number">1</span>] = <span class="number">3</span>;</span><br><span class="line">numbers[<span class="number">2</span>] = <span class="number">5</span>;</span><br><span class="line">numbers[<span class="number">3</span>] = <span class="number">7</span>;</span><br><span class="line">numbers[<span class="number">4</span>] = <span class="number">9</span>;</span><br><span class="line">numbers[<span class="number">5</span>] = <span class="number">11</span>;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>获取某一数组可以用：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 得到数组中第三个数字</span></span><br><span class="line"><span class="type">int</span> <span class="variable">num</span> <span class="operator">=</span> numbers[<span class="number">2</span>];</span><br><span class="line">System.out.println(numbers);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<p>长度</p>
<ul>
<li>数组坐标从0开始</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line">  <span class="type">int</span>[] numbers = <span class="keyword">new</span> <span class="title class_">int</span>[<span class="number">8</span>];<span class="comment">//数组定义方式;</span></span><br><span class="line"></span><br><span class="line">  <span class="type">int</span> <span class="variable">size</span> <span class="operator">=</span> numbers.length;</span><br><span class="line">  System.out.println(size);</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//size可以计算数组长度</span></span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<ul>
<li>int 类型的数据默认值是0;</li>
<li>String类型的数据默认值是null</li>
</ul>
<h4 id="4-3-使用for循环"><a href="#4-3-使用for循环" class="headerlink" title="4.3 使用for循环"></a>4.3 使用for循环</h4><p>用代码解释</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">String[] tables = <span class="keyword">new</span> <span class="title class_">String</span>[<span class="number">3</span>];</span><br><span class="line"></span><br><span class="line">tables[<span class="number">0</span>] = <span class="string">&quot;张三&quot;</span>;</span><br><span class="line">tables[<span class="number">1</span>] = <span class="string">&quot;李四&quot;</span>;</span><br><span class="line">tables[<span class="number">2</span>] = <span class="string">&quot;王五&quot;</span>;</span><br><span class="line"><span class="keyword">for</span>(<span class="type">int</span> i;i&lt;names.length;i++)&#123;<span class="comment">//利用for循环输出</span></span><br><span class="line">    <span class="type">String</span> <span class="variable">name</span> <span class="operator">=</span>tables[i];</span><br><span class="line">    System.out.println(name);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//也可以通过如下来赋值数组;</span></span><br><span class="line">String[] tanles = <span class="keyword">new</span> <span class="title class_">String</span>[]&#123;<span class="string">&quot;张三&quot;</span>,<span class="string">&quot;李四&quot;</span>,<span class="string">&quot;王五&quot;</span>&#125;;</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span>(<span class="type">int</span> <span class="variable">i</span> <span class="operator">=</span> <span class="number">0</span>; i &lt; tables.length; i++)&#123;</span><br><span class="line">  <span class="type">String</span> <span class="variable">name</span> <span class="operator">=</span> tables[i];</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//也可以这样输出</span></span><br><span class="line"><span class="keyword">for</span>(String tanle : tanles) &#123;</span><br><span class="line">    System.out.println(tanle);</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//缺点，无法输出位置;</span></span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title function_">main</span><span class="params">(String[] args)</span> &#123;</span><br><span class="line"></span><br><span class="line">  <span class="keyword">for</span> (<span class="type">int</span> <span class="variable">i</span> <span class="operator">=</span> <span class="number">1</span>; i &lt;= <span class="number">3</span>; i++) &#123;</span><br><span class="line">    <span class="type">String</span> <span class="variable">line</span> <span class="operator">=</span> <span class="string">&quot;&quot;</span>;<span class="comment">//从0开始存储数据;</span></span><br><span class="line">    <span class="keyword">for</span> (<span class="type">int</span> <span class="variable">j</span> <span class="operator">=</span> <span class="number">1</span>; j &lt;= i; j++) &#123;</span><br><span class="line">      <span class="comment">// 拼接line字符串，打印出 类似 1*2=2 2*2=4 这样的效果</span></span><br><span class="line">      line = line + j + <span class="string">&quot;*&quot;</span> + i + <span class="string">&quot;=&quot;</span> + j * i + <span class="string">&quot; &quot;</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    System.out.println(line);</span><br><span class="line">  &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="https://liqur.xyz">SuperXCR</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://liqur.xyz/SuperXCR/24bd5933.html">https://liqur.xyz/SuperXCR/24bd5933.html</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://liqur.xyz" target="_blank">SuperXCR</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/Java/">Java</a></div><div class="post_share"><div class="social-share" data-image="https://liqur-1309874423.cos.ap-shanghai.myqcloud.com/java6.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/SuperXCR/3608f6dd.html" title="Java基础学习（2）"><img class="cover" src="https://liqur-1309874423.cos.ap-shanghai.myqcloud.com/sceney5.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">Java基础学习（2）</div></div></a></div><div class="next-post pull-right"><a href="/SuperXCR/a574217b.html" title="Markdown基本语法"><img class="cover" src="https://liqur-1309874423.cos.ap-shanghai.myqcloud.com/Markdown.jpeg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">Markdown基本语法</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="/SuperXCR/3608f6dd.html" title="Java基础学习（2）"><img class="cover" src="https://liqur-1309874423.cos.ap-shanghai.myqcloud.com/sceney5.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-08-31</div><div class="title">Java基础学习（2）</div></div></a></div><div><a href="/SuperXCR/8eb491b8.html" title="Java基础学习（3）"><img class="cover" src="https://liqur-1309874423.cos.ap-shanghai.myqcloud.com/sceney4.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2022-08-31</div><div class="title">Java基础学习（3）</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">SuperXCR</div><div class="author-info__description">今日事，今日毕</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">16</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">15</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">8</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xxxxxx"><i class="fab fa-github"></i><span>Follow Me</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">This is my Blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8F%98%E9%87%8F%E5%92%8C%E7%B1%BB%E5%9E%8B"><span class="toc-number">1.</span> <span class="toc-text">变量和类型</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-1-%E5%8F%98%E9%87%8F"><span class="toc-number">1.1.</span> <span class="toc-text">1.1 变量</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#1-2-%E8%B5%8B%E5%80%BC"><span class="toc-number">1.2.</span> <span class="toc-text">1.2 赋值</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#1-3-%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="toc-number">1.3.</span> <span class="toc-text">1.3 数据类型</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%AD%97%E7%AC%A6%E4%B8%B2"><span class="toc-number">1.3.1.</span> <span class="toc-text">字符串</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E6%95%B0%E5%AD%97"><span class="toc-number">1.3.2.</span> <span class="toc-text">数字</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%B8%83%E5%B0%94"><span class="toc-number">1.3.3.</span> <span class="toc-text">布尔</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#1-4-%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-number">1.4.</span> <span class="toc-text">1.4 运算符</span></a><ol class="toc-child"><li class="toc-item toc-level-6"><a class="toc-link" href="#%E6%B3%A8%E6%84%8F"><span class="toc-number">1.4.0.1.</span> <span class="toc-text">注意</span></a></li></ol></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#1-5-%E6%95%B0%E5%AD%A6%E5%87%BD%E6%95%B0"><span class="toc-number">1.5.</span> <span class="toc-text">1.5 数学函数</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#1-5-1-%E8%8E%B7%E5%8F%96%E9%9A%8F%E6%9C%BA%E6%95%B0"><span class="toc-number">1.5.1.</span> <span class="toc-text">1.5.1 获取随机数</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#1-5-2-%E7%B1%BB%E5%9E%8B%E8%BD%AC%E6%8D%A2%E6%96%B9%E6%B3%95"><span class="toc-number">1.5.2.</span> <span class="toc-text">1.5.2 类型转换方法</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#1-5-%E8%87%AA%E5%AE%9A%E4%B9%89%E6%96%B9%E6%B3%95"><span class="toc-number">1.6.</span> <span class="toc-text">1.5 自定义方法</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#1-6-%E8%87%AA%E5%AE%9A%E4%B9%89%E6%96%B9%E6%B3%95%E8%B0%83%E7%94%A8"><span class="toc-number">1.7.</span> <span class="toc-text">1.6 自定义方法调用</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#1-7-%E6%96%B9%E6%B3%95%E5%8F%82%E6%95%B0"><span class="toc-number">1.8.</span> <span class="toc-text">1.7 方法参数</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%BD%A2%E5%8F%82"><span class="toc-number">1.8.1.</span> <span class="toc-text">形参</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E5%AE%9E%E5%8F%82"><span class="toc-number">1.8.2.</span> <span class="toc-text">实参</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#1-8-%E5%A4%9A%E5%8F%82%E6%95%B0%E6%96%B9%E6%B3%95"><span class="toc-number">1.9.</span> <span class="toc-text">1.8 多参数方法</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%80%BB%E8%BE%91%E8%AF%AD%E5%8F%A5"><span class="toc-number">2.</span> <span class="toc-text">逻辑语句</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#2-1-%E6%9D%A1%E4%BB%B6%E6%89%A7%E8%A1%8C"><span class="toc-number">2.1.</span> <span class="toc-text">2.1 条件执行</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-2-%E9%80%89%E6%8B%A9%E6%89%A7%E8%A1%8C"><span class="toc-number">2.2.</span> <span class="toc-text">2.2 选择执行</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-3-%E6%9D%A1%E4%BB%B6%E5%88%A4%E6%96%AD%E9%93%BE"><span class="toc-number">2.3.</span> <span class="toc-text">2.3 条件判断链</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-4-%E5%B5%8C%E5%A5%97%E6%9D%A1%E4%BB%B6"><span class="toc-number">2.4.</span> <span class="toc-text">2.4 嵌套条件</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-5-%E8%BF%94%E5%9B%9E%E8%AF%AD%E5%8F%A5"><span class="toc-number">2.5.</span> <span class="toc-text">2.5 返回语句</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-6-%E9%80%92%E5%BD%92"><span class="toc-number">2.6.</span> <span class="toc-text">2.6 递归</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9C%89%E8%BF%94%E5%9B%9E%E5%80%BC%E6%96%B9%E6%B3%95"><span class="toc-number">3.</span> <span class="toc-text">有返回值方法</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#3-1-%E8%BF%94%E5%9B%9E%E5%80%BC"><span class="toc-number">3.1.</span> <span class="toc-text">3.1 返回值</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3-2-%E5%B8%83%E5%B0%94-amp-amp-%E9%80%BB%E8%BE%91%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="toc-number">3.2.</span> <span class="toc-text">3.2 布尔&amp;&amp;逻辑运算符</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%BE%AA%E7%8E%AF"><span class="toc-number">4.</span> <span class="toc-text">循环</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#4-1-%E8%87%AA%E5%A2%9E%E5%92%8C%E8%87%AA%E5%87%8F"><span class="toc-number">4.1.</span> <span class="toc-text">4.1 自增和自减</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#4-2-%E6%95%B0%E7%BB%84"><span class="toc-number">4.2.</span> <span class="toc-text">4.2 数组</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#4-3-%E4%BD%BF%E7%94%A8for%E5%BE%AA%E7%8E%AF"><span class="toc-number">4.3.</span> <span class="toc-text">4.3 使用for循环</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/SuperXCR/7f8be62d.html" title="你不会还不会安装Maven吧"><img src="https://liqur-1309874423.cos.ap-shanghai.myqcloud.com/SuperXCR/%E5%BE%AE%E4%BF%A1%E5%9B%BE%E7%89%87_20230310162508.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="你不会还不会安装Maven吧"/></a><div class="content"><a class="title" href="/SuperXCR/7f8be62d.html" title="你不会还不会安装Maven吧">你不会还不会安装Maven吧</a><time datetime="2023-03-10T09:57:23.000Z" title="发表于 2023-03-10 17:57:23">2023-03-10</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/SuperXCR/c24675b4.html" title="MySQL"><img src="https://liqur-1309874423.cos.ap-shanghai.myqcloud.com/MySQL%E9%85%8D%E7%BD%AE/mysql.webp" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="MySQL"/></a><div class="content"><a class="title" href="/SuperXCR/c24675b4.html" title="MySQL">MySQL</a><time datetime="2022-11-21T06:48:00.000Z" title="发表于 2022-11-21 14:48:00">2022-11-21</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/SuperXCR/bfa56f5e.html" title="Navicat_Premium_16破解"><img src="https://liqur-1309874423.cos.ap-shanghai.myqcloud.com/s1.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Navicat_Premium_16破解"/></a><div class="content"><a class="title" href="/SuperXCR/bfa56f5e.html" title="Navicat_Premium_16破解">Navicat_Premium_16破解</a><time datetime="2022-09-26T02:55:58.000Z" title="发表于 2022-09-26 10:55:58">2022-09-26</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/SuperXCR/b2444a9.html" title="MySQL安装配置"><img src="https://liqur-1309874423.cos.ap-shanghai.myqcloud.com/MySQL%E9%85%8D%E7%BD%AE/mysql.webp" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="MySQL安装配置"/></a><div class="content"><a class="title" href="/SuperXCR/b2444a9.html" title="MySQL安装配置">MySQL安装配置</a><time datetime="2022-09-24T03:30:42.000Z" title="发表于 2022-09-24 11:30:42">2022-09-24</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/SuperXCR/a219e661.html" title="羊了个羊17最新版"><img src="https://liqur-1309874423.cos.ap-shanghai.myqcloud.com/s6.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="羊了个羊17最新版"/></a><div class="content"><a class="title" href="/SuperXCR/a219e661.html" title="羊了个羊17最新版">羊了个羊17最新版</a><time datetime="2022-09-16T05:18:03.000Z" title="发表于 2022-09-16 13:18:03">2022-09-16</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By SuperXCR</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.umd.min.js"></script><div class="js-pjax"></div><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><!-- hexo injector body_end start --><script>
    // 全局变量声明区域
    var fdata = {
      apiurl: 'https://hexo-friendcircle-api-ai9d4hwad-anzhiyu-c.vercel.app/api',
      initnumber: 20, //【可选】页面初始化展示文章数量
      stepnumber: 10, //【可选】每次加载增加的篇数
      error_img: 'https://npm.elemecdn.com/akilar-candyassets/image/404.gif' //【可选，头像图片加载失败时的默认头像】
    }
    //存入本地存储
    localStorage.setItem("fdatalist",JSON.stringify(fdata))
    </script>
    <script defer src="https://npm.elemecdn.com/hexo-filter-fcircle/assets/js/fetch.min.js"></script><script data-pjax>
  function butterfly_clock_anzhiyu_injector_config(){
    var parent_div_git = document.getElementsByClassName('sticky_layout')[0];
    var item_html = '<div class="card-widget card-clock"><div class="card-glass"><div class="card-background"><div class="card-content"><div id="hexo_electric_clock"><img class="entered loading" id="card-clock-loading" src="https://cdn.cbd.int/hexo-butterfly-clock-anzhiyu/lib/loading.gif" style="height: 120px; width: 100%;" data-ll-status="loading"/></div></div></div></div></div>';
    console.log('已挂载butterfly_clock_anzhiyu')
    if(parent_div_git) {
      parent_div_git.insertAdjacentHTML("afterbegin",item_html)
    }
  }
  var elist = 'null'.split(',');
  var cpage = location.pathname;
  var epage = 'all';
  var qweather_key = 'b16a1fa0e63c46a4b8f28abfb06ae3fe';
  var gaud_map_key = 'e2b04289e870b005374ee030148d64fd&s=rsv3';
  var baidu_ak_key = 'undefined';
  var flag = 0;
  var clock_rectangle = '112.982279,28.19409';
  var clock_default_rectangle_enable = 'false';

  for (var i=0;i<elist.length;i++){
    if (cpage.includes(elist[i])){
      flag++;
    }
  }

  if ((epage ==='all')&&(flag == 0)){
    butterfly_clock_anzhiyu_injector_config();
  }
  else if (epage === cpage){
    butterfly_clock_anzhiyu_injector_config();
  }
  </script><script src="https://widget.qweather.net/simple/static/js/he-simple-common.js?v=2.0"></script><script data-pjax src="https://cdn.cbd.int/hexo-butterfly-clock-anzhiyu/lib/clock.min.js"></script><script async src="/js/ali_font.js"></script><!-- hexo injector body_end end --></body></html>